package com.sai.open.sky;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;

import com.skymobi.moposns.mutilopen.login.AcountInfo;
import com.skymobi.moposns.mutilopen.login.LoginUtil;
import com.mrpoid.utils.PLog;
import android.widget.Toast;
import android.content.Context;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.view.View.OnClickListener;
import android.view.View;
import com.skymobi.moposns.mutilopen.MultiOpenActivity;
import android.widget.EditText;
import com.skymobi.moposns.MoposnsLogoActivity;
import com.skymobi.plugin.api.fragment.FGUtil;
import com.skymobi.moposns.api.bean.AppInfo;
import com.skymobi.moposns.mutilopen.util.MrpConst;
import com.sai.open.BaseActivity;
import android.widget.ListView;
import android.widget.AdapterView;
import android.widget.Adapter;
import com.sai.open.mrp.ListAdapter;
import com.sai.open.mrp.MopoConst;
import com.sai.open.mrp.MrpDef;
import cn.sharesdk.framework.ShareSDK;
import com.skymobi.moposns.pluginupdate.GetPluginUpdatePostfixBiz;
import java.util.Timer;
import java.util.TimerTask;
import com.sai.open.App;

public class MainActivity extends BaseActivity implements AdapterView.OnItemClickListener
{
	AcountInfo info = null;
	LoginUtil loginUtil = new LoginUtil();

	public ListView listView = null;


	@Override
	public void onItemClick(AdapterView<?> p1, View p2, int p3, long p4)
	{
		// TODO: Implement this method
		MrpDef mrp = MopoConst.mrpInfo.get(p3);
		if (mrp != null)
		{
			if (!loginUtil.isAccountLogined())
				toLogin();
			else
				startMrp(mrp);
		}
		else
			toast("非冒泡网游，无法启动");
	}

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pages_select);
		
		listView = findViewById(R.id.p_select_list);
		listView.setOnItemClickListener(this);

		ListAdapter myAdapter = new ListAdapter(this);
		myAdapter.setListData(MopoConst.mrpInfo);
		listView.setAdapter(myAdapter);

		changeFont();
	}

	//去登录
	private void toLogin()
	{
		Intent intent = new Intent(this, LoginActivity.class);
		startActivity(intent);
	}

	public void startMrp(MrpDef mrp)
	{
		startMrpEntity(this, getApplicationInfo().loadLabel(getPackageManager()).toString(), mrp.entry, mrp.showname);
	}

	public void startMrpEntity(Context context, String entra, String url, String name)
	{
        Intent intent = new Intent();
		intent.putExtra("launchEntrace", entra);
		intent.putExtra("name_url", url);
		intent.putExtra("appname", name);
		intent.putExtra("type", 1);
		intent.putExtra("entry", "startMrp");
		FGUtil.launchActivity(context, intent.addFlags(0x10000000), "com.skymobi.moposns.mrpmanager.keep.MrpManagerFragment");
    }
}
